//
//  DLDatePickerView.m
//  UIDatePicker-时间选择器
//
//  Created by 王道林 on 16/9/26.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "DLDatePickerView.h"

@interface DLDatePickerView ()

@end


@implementation DLDatePickerView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
   self = [super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}


- (void)createSubview
{
    
    _datePicker = [[UIDatePicker alloc] init];
    _datePicker.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 40);
    _datePicker.date = [NSDate date];
    _datePicker.timeZone = [NSTimeZone timeZoneWithName:@"GTM+8"];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    _datePicker.maximumDate = [NSDate date];
    [self addSubview:_datePicker];
    
    
    _button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.frame = CGRectMake(0,self.frame.size.height - 50 , self.frame.size.width, 40);
    [self addSubview:_button];
    [_button setTitle:@"确定" forState:UIControlStateNormal];
    _button.titleLabel.font = [UIFont systemFontOfSize:20];
    [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
}


- (void)buttonAction:(UIButton *)button
{
    NSDate *nowDate = [_datePicker date];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateFormatterString = [dateFormatter stringFromDate:nowDate];
    self.buttonGetDateBlock(dateFormatterString);
}








@end
